<%@page import="org.jackysoft.report.ProductValidation"%>
<%@ page contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib  uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib  uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib  uri="http://www.joda.org/joda/time/tags" prefix="joda" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="../commons/headfiles-jquery.jsp" %>
<title>合同浏览</title>
<link  href="../css/apps/contract/edit.css" rel="stylesheet" />
<script src="${sbase }scripts/arttemp/template.js"></script>
<script type="text/javascript">
template.openTag = '<#';
template.closeTag = '#>';

var gindex = 0;
</script>
<script id="dataLine" type="text/html">
<tr>

  <td>
     <input class="codename" readonly="readonly" name="bean.contractItems[<#=index#>].owner.code" value="<#=code#>" />
  </td>
  <td>
     <input class="codename" readonly="readonly" name="bean.contractItems[<#=index#>].owner.name" value="<#=name#>" />
  </td> 
  <td><input  class="number-field" name="bean.contractItems[<#=index#>].validation" value="<#=validation#>" /></td> 
  
  <td>
     <input  class="number-field" name="bean.contractItems[<#=index#>].price" value="<#=price#>" />
     <input  type="hidden"  name="bean.contractItems[<#=index#>].client.id" value="${bean.client.id}" />
     <input  type="hidden"  name="bean.contractItems[<#=index#>].contract.id" value="${bean.id}" />
     
  </td>
  <td></td>
  <td><input  class="number-field" name="bean.contractItems[<#=index#>].storage" value="<#=storage#>" /></td> 
  <td><input  class="number-field" name="bean.contractItems[<#=index#>].remark" value="<#=remark#>" /></td> 
  <td><input  type="text" readonly name="bean.contractItems[<#=index#>].contractType" value="<#=contractType#>" /></td> 
  <td><a href="javascript:;" onclick="removeMe(this)"><img src="${sbase}images/removeMe.gif"/> </a></td>
</tr>
 <tr>            
 <# for (var r=0;r<list.length;r++) { #> 
	<td>
       <input  type="hidden"  name="bean.contractItems[<#=index#>].dataItems[<#=r#>].month" value="<#=list[r].month#>" />
        <ul>
         <li><input  class="number-field" name="bean.contractItems[<#=index#>].dataItems[<#=r#>].assumpsit" value="<#=list[r].assumpsit#>" />   </li>
         <li><input  class="number-field" name="bean.contractItems[<#=index#>].dataItems[<#=r#>].custom" value="<#=list[r].custom#>"   />   </li>
        </ul>
    </td>                
 <#}#> 
  <td><a href="javascript:;" onclick="removeMe(this)"><img src="${sbase}images/removeMe.gif"/> </a></td>
</tr>
</script>
</head>
<body>
<form id="cform">

	<input type="hidden" name="bean.id" value="${bean.id }"  />
  	<input type="hidden" name="bean.security"  value="${bean.security }" readonly="readonly"/>
    <input type="hidden" name="bean.dueDate" value="${bean.dueDate}" />
    <input type="hidden" name="bean.name"  value="${bean.name}" readonly="readonly"/>
    <input type="hidden" name="bean.client.id"  value="${bean.client.id}" readonly="readonly"/>
<div class="alert alert-info">
<h4>${bean.name}号合同</h4>
<dl>
  <dd>合同号:${bean.name}</dd>
  <dd>客户    :${bean.client.name}</dd>
  <dd>总额   :${bean.amount}</dd>
</dl>
</div>
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<tr>
  <th colspan="13" class="btn-group"> 
  <button class="btn btn-success" id="itemBtn" type="button">添加数据项</button>
   <button class="btn btn-info" type="button" onclick="updateOne()">保存</button>
  </th>
</tr>
<tr>
 <th>代码 </th>
 <th>名称 </th>
 <th>验收状态 </th>
 <th>总量/价格</th>
 <th>总额</th>
 <th>库存总量</th>
 <th>约定事项</th> 
 <th>合同类型</th> 
 <th colspan="5">管理</th>
</tr>
</thead>
 
<tbody id="pdtBody">
  <script type="text/javascript">
     gindex = '${fn:length(bean.contractItems)}';
  </script>
 <c:forEach items="${bean.contractItems}" var="item" varStatus="vs">
 <tr class="success">
  <td>
   
   <input type="hidden" name="bean.contractItems[${vs.index}].id" value="${item.id}" />    
   <input type="text" name="bean.contractItems[${vs.index}].owner.code" value="${item.owner.code}" 
      readOnly="readonly"
   />    
  
  </td>
  <td>${item.owner.name}</td> 
  <td>
  <%
    ProductValidation[] vadors  = ProductValidation.values();
    pageContext.setAttribute("vadors", vadors);
  %>
  <select id="validation_${item.id }" name="bean.contractItems[${vs.index}].validation" class="remark">
  <c:forEach items="${vadors}" var="vad">
     <option value="${vad }" ${vad==item.validation?"selected":""}>${vad}</option>
  </c:forEach>
   </select>
  </td>
  <td>${item.amount}/<label class="label">${item.price}</label></td>
  <td>${item.itemAmount}</td>
  <td>
    <input name="bean.contractItems[${vs.index}].storage" value="${item.storage}" id="storage_${item.id}" class="number-field" />
  </td>
  <td >
    <input name="bean.contractItems[${vs.index}].remark" id="remark_${item.id}"  value="${item.remark}" class="remark"  />
           
  </td>
  <td >
    <input name="bean.contractItems[${vs.index}].contractType"   value="${item.contractType}"  readonly />
           
  </td>
  <td colspan="5">
      <div class="btn btn-group">
     <button type="button" class="btn btn-small btn-primary" onclick="editItem('${item.id}')">
      <i class="icon-white icon-edit"></i>保存
     </button>    
     
     <button  type="button" class="btn btn-small btn-info" onclick="submitRepo('${item.owner.code}','${bean.id}','${item.id}')">
        <i class="icon-white icon-chevron-up"></i>缴库
     </button>
     
      <button  type="button" class="btn btn-success btn-small" onclick="showSubmits('${bean.id}','${item.owner.code}','${item.id}')">
        <i class="icon-white icon-eye-open">显示缴库记录</i>
      </button>
     
     <button  type="button" class="btn btn-small btn-danger" onclick="removeItem(this,'${bean.id}','${item.id}')">
      <i class="icon-white icon-remove"></i>删除
     </button> 
       
    </div>
  </td>
  
 </tr> 

  <tr class="info">
    <td >月份</td>
     <c:forEach items="${item.dataItems}" var="ditem" varStatus="ds">
    
    <td>
     <input name="bean.contractItems[${vs.index}].dataItems[${ds.index}].month" 
      type="hidden"
      value="${ditem.month}" />
    <div class="btn btn-group">
      <button  type="button"  class="btn btn-info btn-mini" onclick="editDetail('${ditem.id}')">
        <i class="icon-white icon-edit"></i>
        <span class="label label-info">${ditem.month}月</span>
      </button>     
    </div>
    </td>
   </c:forEach>
   </tr>
   
   <tr>
   <td>[合同/缴库]</td>
       <c:forEach items="${item.dataItems}" var="ditem">
       		<td>
       		<div class="input-append">
       		<input name="bean.contractItems[${vs.index}].dataItems[${ds.index}].assumpsit" 
       		       id="ditem_assumpsit_${ditem.id}"  value="${ditem.assumpsit}" class="number-field"   />
       		<label class="label label-success">${ditem.custom}</label>
       		<input name="bean.contractItems[${vs.index}].dataItems[${ds.index}].custom"  
       		       id="ditem_custom_${ditem.id}" type="hidden"  value="${ditem.custom}"  />
       		</div>
       		</td>
	  		
	   </c:forEach>  
   </tr>
   

 
   <tr>
   <td colspan="13">
     <ul id="${item.id}_submitation">
         
     </ul>
   </td>
   </tr>
      
 </c:forEach>
</tbody>
<tfoot>
  <tr>
    <td>备注</td>
    <td colspan="18">
     
      <textarea name="bean.remark">${bean.remark}</textarea>
     
    </td>
  </tr>
</tfoot>
</table>

</form>
<script type="text/javascript" src="../scripts/apps/contract/edit.js"></script>

</body>
</html>